<?php
final class Loader extends autoloader implements interface_loader {
    private $registry;
    private $paths;

    public function __construct(Registry $registry) {
        parent::__construct();
        $this->paths = array();
        $this->registry = $registry;
    }

    public function set_paths($paths) {
        $this->paths = array_merge($this->paths, $paths);
    }

    public function set_path($resource, $path){
        $this->paths[$resource] = $path;
    }

    public function get_path($resource){
        return isset($this->paths[$resource]) ? $this->paths[$resource] : null;
    }

    public function config($app_id){
        $cfg = new Config($this->paths['dir_config'] . $app_id . '.ini');
        return $cfg;
    }

    public function library($library) {

        $dir = $this->paths['dir_library'] . $library . '/';

        $this->add_path_array(array(
            $dir,
            $dir . 'interface/',
            $dir . 'abstract/',
            $dir . 'class/'
        ));
    }

    public function get_app($app_id) {
        $config = $this->config($app_id);
        $path = $config->set_section('paths')->get('dir_app');
        $file = $path . $app_id . '.php';
        include_once($file);
        return new $app_id($this->registry, $config);
    }

} 
?>
